extends MarginContainer
class_name FactionListItem

signal faction_checked

var _parent:Node
var _button:Button
var _check_texture_react:TextureRect
var _label:Label

var faction_index:int = 0

var _faction_entity:FactionEntity
var faction_entity:FactionEntity:
	get:
		return _faction_entity
	set(value):
		_faction_entity = value
		_label.text = value.faction_name
	
func _ready():
	_parent = get_parent()
	_check_texture_react = get_node("HBoxContainer/MarginContainer/CheckTextureRect")
	_button = get_node("CheckButton")
	_label = get_node("HBoxContainer/MarginContainer2/Label")
	_button.pressed.connect(_on_check_button_clicked)
	pass

func  _on_check_button_clicked():
	var children = _parent.get_children()
	if children.size() == 0 :
		return
	for item in children:
		item.call("reset_check_statu")
		pass
	check_faction()
	faction_checked.emit(self)
	pass
	
func check_faction():
	_check_texture_react.show()
	pass
	
func reset_check_statu():
	_check_texture_react.hide()
	pass
